package com.by.common.group;

import com.by.common.exception.ValidateException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/2/14 16:13
 * @since JDK1.8
 */
public class V {

    public static void validate(BindingResult result) {
        List<FieldError> errors = result.getFieldErrors();
        if (errors != null && errors.size() > 0) {
            Map<String,String> map = new HashMap<>();
            errors.forEach((item)->{
                map.put(item.getField(),item.getDefaultMessage());
            });
            throw new ValidateException(map);
        }
    }
}
